package gold.digger;

import gold.utils.InputUtil;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC1629 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public char slowestKey(int[] releaseTimes, String keysPressed) {
            int maxIdx = 0, maxDur = releaseTimes[0];
            for (int i = 1; i < releaseTimes.length; i++) {
                if (releaseTimes[i] - releaseTimes[i - 1] > maxDur ||
                        (releaseTimes[i] - releaseTimes[i - 1] == maxDur && keysPressed.charAt(i) > keysPressed.charAt(maxIdx))) {
                    maxDur = releaseTimes[i] - releaseTimes[i - 1];
                    maxIdx = i;
                }
            }

            return keysPressed.charAt(maxIdx);
        }
    }

    public void run() {
        Solution solution = new Solution();
//        输入：releaseTimes = [9,29,49,50], keysPressed = "cbcd"
//        输出："c"
        int[] arr = InputUtil.toIntegerArray("[9,29,49,50]");
        System.out.println(solution.slowestKey(arr, "abcd"));

//        输入：releaseTimes = [12,23,36,46,62], keysPressed = "spuda"
//        输出："a"
        int[] arr1 = InputUtil.toIntegerArray("[12,23,36,46,62]");
        System.out.println(solution.slowestKey(arr1, "spuda"));

//        [1,2]
//        "ba"
        int[] arr2 = InputUtil.toIntegerArray("[1,2]");
        System.out.println(solution.slowestKey(arr2, "ba"));
    }

    public static void main(String[] args) throws Exception {
        LC1629 an = new LC1629();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
